package com.hsl.study.config;

import com.hsl.study.listener.TestChatModelListener;
import com.hsl.study.servcie.MyChatLangChainModel;
import dev.langchain4j.model.chat.ChatLanguageModel;
import dev.langchain4j.model.openai.OpenAiChatModel;
import dev.langchain4j.service.AiServices;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.time.Duration;
import java.util.List;

/**
 * @Author: hsl
 * @CreateTime: 2025-03-12  16:31
 */
@Configuration
public class MyChatLangChainModelConfig {

    @Bean
    public ChatLanguageModel ChatLanguageModel(){
        return OpenAiChatModel.builder()
//                .apiKey(System.getenv("LANGCHAIN_DEEPSEEK"))
//                .baseUrl("https://api.deepseek.com/v1")
//                .modelName("deepseek-chat")
                .apiKey(System.getenv("LANGCHAIN_QIANQWEN"))
                .baseUrl("https://dashscope.aliyuncs.com/compatible-mode/v1")
                .modelName("qwen-turbo-0624")
                .logRequests(true)
                .logResponses(true)
                .listeners(List.of(new TestChatModelListener()))
                .build();
    }

    @Bean
    public MyChatLangChainModel myChatLangChainModel(ChatLanguageModel chatLanguageModel) {
        return AiServices.create(MyChatLangChainModel.class,chatLanguageModel);
    }
}
